package com.heima.article.controller.v1;


import com.cjq.apis.article.IArticleClient;
import com.heima.article.service.ApArticleService;
import com.heima.common.constant.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章相关接口")
public class ApArticleController implements IArticleClient {

    @Autowired
    private ApArticleService articleService;
    @PostMapping("/load")
    @ApiOperation("加载首页")

    public ResponseResult load(@RequestBody ArticleHomeDto articleHomeDto){
        return articleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    @PostMapping("/loadmore")
    @ApiOperation("加载更多")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto articleHomeDto){
        return articleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }


    @PostMapping("/loadnew")
    @ApiOperation("加载最新")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto articleHomeDto){

        return articleService.load(articleHomeDto, ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    @PostMapping("/save")
    @Override
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) {
        return articleService.saveArticle(dto);
    }

}
